def get_trna_dict(mycoplasma=False):
    trnaDict = {
            'Phe1': ['TTT', 'TTC'],
            'Leu1': ['TTA', 'TTG'],
            'Leu2': ['CTT', 'CTC'],
            'Leu3': ['CTA', 'CTG'],
            'Ile1': ['ATT', 'ATC'],
            'Ile2': ['ATA'],
            'Met1': ['ATG'],
            'Val1': ['GTT', 'GTC'],
            'Val2': ['GTA', 'GTG'],
            'Ser1': ['TCT', 'TCC'],
            'Ser2': ['TCA', 'TCG'],
            'Ser3': ['AGT', 'AGC'],
            'Pro1': ['CCT', 'CCC'],
            'Pro2': ['CCA', 'CCG'],
            'Thr1': ['ACT', 'ACC'],
            'Thr2': ['ACA', 'ACG'],
            'Ala1': ['GCT', 'GCC'], 
            'Ala2': ['GCA', 'GCG'],
            'Tyr1': ['TAT', 'TAC'],
            'His1': ['CAT', 'CAC'],
            'Glu1': ['CAA', 'CAG'],
            'Asp1': ['AAT', 'AAC'],
            'Lys1': ['AAA', 'AAG'],
            'AsA1': ['GAT', 'GAC'],
            'GlA1': ['GAA', 'GAG'],
            'Cys1': ['TGT', 'TGC'],
            'Trp1': ['TGG'],
            'Arg1': ['CGT', 'CGC'],
            'Arg2': ['CGA', 'CGG'],
            'Arg3': ['AGA', 'AGG'],
            'Gly1': ['GGT', 'GGC'],
            'Gly2': ['GGA', 'GGG']
            }
    if mycoplasma:
        trnaDict['Trp1'] = ['TGG', 'TGA']
    return trnaDict

def get_codon_to_AA_dict(stop=False, mycoplasma=False):
    aaDict = get_AA_dict(stop=True, mycoplasma=mycoplasma)
    codons = [\
        'AAA',\
        'AAC',\
        'AAG',\
        'AAT',\
        'ACA',\
        'ACC',\
        'ACG',\
        'ACT',\
        'AGA',\
        'AGC',\
        'AGG',\
        'AGT',\
        'ATA',\
        'ATC',\
        'ATG',\
        'ATT',\
        'CAA',\
        'CAC',\
        'CAG',\
        'CAT',\
        'CCA',\
        'CCC',\
        'CCG',\
        'CCT',\
        'CGA',\
        'CGC',\
        'CGG',\
        'CGT',\
        'CTA',\
        'CTC',\
        'CTG',\
        'CTT',\
        'GAA',\
        'GAC',\
        'GAG',\
        'GAT',\
        'GCA',\
        'GCC',\
        'GCG',\
        'GCT',\
        'GGA',\
        'GGC',\
        'GGG',\
        'GGT',\
        'GTA',\
        'GTC',\
        'GTG',\
        'GTT',\
        'TAA',\
        'TAC',\
        'TAG',\
        'TAT',\
        'TCA',\
        'TCC',\
        'TCG',\
        'TCT',\
        'TGA',\
        'TGC',\
        'TGG',\
        'TGT',\
        'TTA',\
        'TTC',\
        'TTG',\
        'TTT'\
        ]
    if not stop and not mycoplasma:
        codons.remove('TAA')
        codons.remove('TAG')
        codons.remove('TGA')
    elif not stop and mycoplasma:
        codons.remove('TAA')
        codons.remove('TAG')

    codonDict = {}
    for codon in codons:
        for aa in aaDict:
            if codon in aaDict[aa]:
                codonDict[codon] = aa
    return codonDict

def get_AA_dict(stop=False, mycoplasma=False):
    aaDict =  {\
        'phenylalanine': ['TTT', 'TTC'],\
        'leucine': ['CTT', 'CTC', 'CTA', 'CTG', 'TTA', 'TTG'], \
        'isoleucine': ['ATT', 'ATC', 'ATA'],\
        'methionine': ['ATG'],\
        'valine': ['GTT', 'GTC', 'GTA', 'GTG'],\
        'serine': ['TCT', 'TCC', 'TCA', 'TCG', 'AGT', 'AGC'],\
        'proline': ['CCT', 'CCC', 'CCA', 'CCG'],\
        'threonine': ['ACT', 'ACC', 'ACA', 'ACG'],\
        'alanine': ['GCT', 'GCC', 'GCA', 'GCG'],\
        'tyrosine': ['TAT', 'TAC'],\
        'histidine': ['CAT', 'CAC'],\
        'glutamine': ['CAA', 'CAG'],\
        'asparagine': ['AAT', 'AAC'],\
        'lysine': ['AAA', 'AAG'],\
        'aspartic_acid': ['GAT', 'GAC'],\
        'glutamic_acid': ['GAA', 'GAG'],\
        'cysteine': ['TGT', 'TGC'],\
        'arginine': ['CGT', 'CGC', 'CGA', 'CGG', 'AGA', 'AGG'],\
        'glycine': ['GGT', 'GGC', 'GGA', 'GGG'],\
        'tryptophan': ['TGG'], \
        }
    if stop:
        aaDict['stop'] = ['TAA', 'TAG', 'TGA']
    if mycoplasma:
        aaDict['tryptophan'] = ['TGG', 'TGA']
    if mycoplasma and stop:
        aaDict['stop'] = ['TAA', 'TAG']
    return aaDict

def get_aa_to_trna_dict(aaToCodonDict, codonToTRNAdict):
    dicty = {}
    for aa in aaToCodonDict.keys():
        listy = []
        for codon in aaToCodonDict[aa]:
            listy.append(codonToTRNAdict[codon])
        dicty[aa] = list(set(listy))
    return dicty

def get_codon_to_trna_dict(trnaDict):
    dicty = {}
    for trna in trnaDict.keys():
        for codon in trnaDict[trna]:
            dicty[codon] = trna
    return dicty

def get_dictionaries(mycoplasma=False):
    aaToCodonDict = get_AA_dict(stop=False, mycoplasma=mycoplasma)
    codonToAAdict = get_codon_to_AA_dict(stop=False, mycoplasma=mycoplasma)
    trnaToCodonDict = get_trna_dict(mycoplasma=mycoplasma)
    codonToTRNAdict = get_codon_to_trna_dict(trnaToCodonDict)
    aaToTRNAdict = get_aa_to_trna_dict(aaToCodonDict, codonToTRNAdict)
    return aaToCodonDict, codonToAAdict, trnaToCodonDict, codonToTRNAdict, aaToTRNAdict
